library(DiagrammeR)
## Warning: package 'DiagrammeR' was built under R version 3.5.2
library(dplyr)
## Warning: package 'dplyr' was built under R version 3.5.2
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(tidyr)
## Warning: package 'tidyr' was built under R version 3.5.2
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.5.2
library(grDevices)
require(hhi)
## Loading required package: hhi
require(data.table)
## Loading required package: data.table
## Warning: package 'data.table' was built under R version 3.5.2
## 
## Attaching package: 'data.table'
## The following objects are masked from 'package:dplyr':
## 
##     between, first, last
theme_set(theme_bw())
render_graph(generate_university_network_df(all, year = 2017, colorByContinent = TRUE))
render_graph(generate_university_network_df(all, year = 2010, colorByContinent = TRUE))
generate_all_graphs <- function(df) {
  data.list <- list()
  for(i in 1:length(unique(df$iteration))) {
    data.list[[i]] <- generate_csss_network_df(df, iter = unique(df$iteration)[i])
  }
  return(data.list)
}
all.graphs <- generate_all_graphs(no.2011)
yearly.compare <- yearly_compare(all.graphs)
avdg <- ggplot(data = yearly.compare) +
  geom_col(mapping = aes(x = graph, y = avg_degree)) +
  coord_flip() +
  labs(y = "Average Degree", x = "Year and Location")
diam <- ggplot(data = yearly.compare) +
  geom_col(mapping = aes(x = graph, y = max_ecct)) +
  coord_flip() +
  labs(y = "Diameter", x = "Year and Location")
path <- ggplot(data = yearly.compare) +
  geom_col(mapping = aes(x = graph, y = avg_path)) +
  coord_flip() +
  labs(y = "Average Path Length", x = "Year and Location")
cons <- ggplot(data = yearly.compare) +
  geom_col(mapping = aes(x = graph, y = avg_const)) +
  coord_flip() +
  labs(y = "Average Constraint", x = "Year and Location")
cowplot::plot_grid(avdg, diam, path, cons)

#degree distribution
palette <- palette(rainbow(17))
dd.plot <- ggplot()

data <- rbindlist(lapply(1:length(all.graphs), function(x) { 
    df <- get_degree_distribution(all.graphs[[x]]) 
    df$network_id <- as.factor(x)
    return(df)
  } 
))

data %>%
  ggplot(aes(x = degree, y = total_degree_dist, color = network_id)) +
  geom_line()

for(i in 2:length(node.data)) {
  print(graph_discp_data(node.data[[i]]))
}